package com.supermali.behavior.jump.land;

import com.supermali.behavior.Gravity;
import com.supermali.behavior.jump.JumpBehavior;
import com.supermali.entity.map.background.dynamic.DynamicBackGroundMapAbstract;

/**
 * 破碎砖块
 * */
public class BreakBrickJump extends JumpBehavior {

    private DynamicBackGroundMapAbstract dynamicBackGroundMapAbstract;


    private double totalTime = 0;

    private double v0y = 40; // 初速度

    private int status = 0;// 0:已结束，1：正在运行

    public BreakBrickJump(DynamicBackGroundMapAbstract dynamicBackGroundMapAbstract) {
        this.dynamicBackGroundMapAbstract = dynamicBackGroundMapAbstract;
        totalTime = 0;
    }

    @Override
    public void jump() {
        double dt = 0.04;
        double g = Gravity.g;
        totalTime+=dt;
        double ds = v0y * dt - g * dt * totalTime;
        double y = this.dynamicBackGroundMapAbstract.getY() + ds;
        this.dynamicBackGroundMapAbstract.setY(y);
    }

    @Override
    public boolean isOver() {
        return status==0?true:false;
    }

    @Override
    public void start() {
        this.status=1;
    }

    @Override
    public void setVy(double vy) {
        this.v0y=vy;
    }
}
